package com.esp.studentManagementSystem.controller;

import com.esp.studentManagementSystem.service.impl.UserMenuServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class UserMenuController {
    private final ObjectMapper mapper = new ObjectMapper();

    @Autowired
    private UserMenuServiceImpl userMenuServiceImpl;

    @GetMapping(value = "/permissions/{userId}", produces = "application/json")
    public String getUserMenu(@PathVariable Integer userId) {
        String jsonString;
        // 将UserMenuDTO对象转换为JSON字符串
        try {
            jsonString = mapper.writeValueAsString(userMenuServiceImpl.getUserMenu(userId));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return jsonString;
    }
}
